import type {
  OrderDetailResult,
  GetMemberOrderPreNowParams,
  OrderCreateParams,
  OrderPreResult
} from '@/types/order'
import type {
  OrderListParams,
  OrderListResult,
  OrderLogisticResult,
  OrderPayResult
} from '@/types/orderList'
import { myGet, myPost, myRequest } from '@/utils/request'

/** 填写订单-获取预付订单 */
export const getMemberOrderPreAPI = () => {
  return myGet<OrderPreResult>('/member/order/pre')
}

/** 获取立即购买订单 */
export const getMemberOrderPreNowAPI = (data: GetMemberOrderPreNowParams) => {
  return myRequest<OrderPreResult>({
    url: '/member/order/pre/now',
    method: 'GET',
    data
  })
}

/** 提交订单 */
export const postMemberOrderAPI = (data: OrderCreateParams) => {
  return myPost<{ id: string }>('/member/order', data)
}

/** 获取订单详情 */
export const getMemberOrderDetailAPI = (id: string) => {
  return myGet<OrderDetailResult>(`/member/order/${id}`)
}

/** 再次购买 */
export const getMemberOrderAgainAPI = (id: string) => {
  return myGet<OrderPreResult>(`/member/order/repurchase/${id}`)
}

/** 模拟发货 */
export const getMemberOrderConsignmentByIdAPI = (id: string) => {
  return myGet(`/member/order/consignment/${id}`)
}

/** 确认收货 */
export const putMemberOrderReceiptByIdAPI = (id: string) => {
  return myRequest<OrderPayResult>({
    method: 'PUT',
    url: `/member/order/${id}/receipt`
  })
}

/** 获取订单物流 */
export const getMemberOrderLogisticsByIdAPI = (id: string) => {
  return myGet<OrderLogisticResult>(`/member/order/${id}/logistics`)
}

/** 删除订单 */
export const deleteMemberOrderAPI = (data: { ids: string[] }) => {
  return myRequest({
    method: 'DELETE',
    url: `/member/order`,
    data
  })
}

/** 获取订单列表 */
export const getOrderListAPI = (params: OrderListParams) => {
  return myGet<OrderListResult>('/member/order', params)
}
